﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TMDT_ProjGroup09_Client.LogisticSystemWebService;
namespace TMDT_ProjGroup09_Client
{
    public partial class ajaxActions : System.Web.UI.Page
    {
        private LogisticSystemSoapClient ws = new LogisticSystemSoapClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            string cmd = Request.QueryString["cmd"];
            if (cmd != null)
            {
                switch (cmd)
                {
                    case "CheckLogin":
                    {
                        if (Session["username"] == null)
                            Response.Write(0);
                        else
                            Response.Write(Session["username"]);
                        break;
                    }
                    case "Login":
                        {
                            string username = Request.QueryString["username"].ToString();
                            string pass = Request.QueryString["pass"].ToString();
                            Session["username"] = username;
                            Response.Write(Session["username"].ToString());

                            break;
                        }
                    case "Logout":
                    {
                        Session["username"] = null;
                        break;
                    }

                    case "GetListChiNhanh":
                    {
                        ChiNhanhDTO[] cnDTO = ws.TableDsChiNhanh();
                        string html = "";
                        foreach (ChiNhanhDTO cn in cnDTO)
                        {
                            html += "<option value='" + cn.MaChiNhanh + "'" + ">" + cn.TenChiNhanh + "</option>";
                        }
                        Response.Write(html);
                        break;
                    }
                    case "Test":
                    {
                        Response.Write("OK");
                        break;
                    }
                }
            }
            string cmdPOST = Request["cmd"];
            if (cmdPOST != null)
            {
                switch (cmdPOST)
                {
                    case "Login":
                        {
                            string username = Request["username"].ToString();
                            string pass = Request["pass"].ToString();
                            Session["username"] = username;
                            if (ws.CheckLogin(username, pass))
                            {
                                Response.Write(Session["username"].ToString());
                            }
                            else
                            {
                                Response.Write(0);
                            }
                            break;
                        }
                }
            }
        }
    }
}